


function [LIP, tau] = computeLIP( d, c , deltaT, isSave)
if nargin <= 2
    deltaT = 9.5017;
    isSave = 0;
end
deltaT = deltaT * 0.001;

Bound = 48.6; %Exp Bound

alpha_0 = 1;
beta_0 = 1;
nT = size(d,1) - alpha_0 - beta_0;

LIP = zeros(nT + 1 , length(c));
Slopes = zeros(length(c),1);

[phi tau] = fitPolicy(d(alpha_0 + beta_0:end,:));

buildupRegion = 1 : 13;

for i =  1 : length(c)
    u = (40*c(i)+20)./(40+20*c(i));       
    LIP(:,i) = (alpha_0 + u * (0:nT)')./(alpha_0 + beta_0 + (0:nT)') ...
       - phi;
    LIP(:,i) = (LIP(:,i) + 0.5) * 2;
    LIP(LIP(:,i) > 1,i) = 1;
    y = LIP(buildupRegion,i) * Bound;
    linCoeff = [(1:length(y))' * (1 + 0.5 * c(i)) * deltaT, ones(length(y),1)] \ y;
    Slopes(i) = linCoeff(1);
end

figure;
plot( deltaT * [0:nT]' * (1 + 0.5 * c'), LIP* Bound)
xlim([0 4]);
ylim([0 Bound]);
xlabel('Time (s)', 'FontWeight', 'bold','FontSize',30);
ylabel('LIP Responses (Spikes/s)', 'FontWeight', 'bold','FontSize',30);
set(gca,  'LineWidth',2,...
    'FontWeight','bold');
set(gcf,'paperunits','inches');
set(gcf,'papersize',[12 18]);
set(gcf,'paperposition',[0,0,12,18]);
if isSave == 1
    saveas(gcf, 'LIPResponses.pdf','pdf');
end


figure;
Buildup = [c, ones(length(c),1)] \ Slopes;
plot(c, c * Buildup(1) + Buildup(2));
hold on;
plot(c, Slopes,'ro','MarkerSize',10);
legend(sprintf('slope = %.1f', Buildup(1)), 'Build up rate');
xlabel('Coherence','FontWeight', 'bold');
ylabel('Build up rate (Spikes/s^2)','FontWeight', 'bold');
%xlim([c0(1), c0(end)]);
set(gcf,'paperunits','inches');
set(gcf,'papersize',[12 18]);
set(gcf,'paperposition',[0,0,12,18]);
if isSave == 1
    saveas(gcf, 'buildupRate.pdf','pdf');
        saveas(gcf, 'buildupRate.fig','fig');
end

end

